<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/style.css" />
		<script src="../js/head_public.js"></script>
		<script src="../js/session.js"></script>
		<script src="../js/common.js"></script>
		<style>
			.yirenzheng{background:#ff7e00;border-radius: 0.5rem;border: none!important;color: #fff!important;margin-top: 0.8rem;}
		    .gengxin{font-size: 0.3rem;color: #666;margin-top: 0.8rem;display: inline-block;}
		    .ding-code{font-size: 14px;color: #666666;border-bottom: 1px solid #EEEEEE;}
		    .ds-name{padding-left: 40px;font-size: 0.35rem;font-weight: normal;color: #323232;background: url(../images/shaoshi-icon.png)no-repeat;background-size: 30px;background-position: 0rem -0.1rem;margin: 0px;height: 25px;line-height: 25px;}
		    .ds-container{overflow: hidden;margin-top:0.2rem ;position: relative;}
		    .gm-jifen{position: absolute;top:0.7rem;left: 2.2rem;color: #ff7e00!important;font-size: 14px;}
		    .money{font-size: 0.4rem;}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav ding-bar">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">待付款</h1>
		</header>
		<div class="mui-content" style="padding-bottom: 0px;">
			<div class=""style="background: #fff;">
		    	<ul class="gongdan-ul">
		    		<li><span>下单时间：</span><span>2019-05-12  21:05:30</span></li>
		    		<li><span>超期时长：</span><span>14时25分36秒</span></li>
		    		<li><span>已用时长：</span><span>1天14时25分36秒</span></li>
		    		<li><span>电梯编号：</span><span>ASDFG123456</span></li>
		    		<li><span>维保单号：</span><span>85214796365</span></li>
		    		<li style="position: relative;"><span>电梯型号：</span><span>直梯</span><button class="chaoqi">超期</button><button class="jixiu">急修</button></li>
		    		<li><span>电梯地址：</span><span>七里河区西湖雅筑小区(西津 东路南)梁家庄-13号楼</span></li>
		    	</ul>
		    </div>
	    	
    	    <div style="background: #fff;padding-bottom: 10px;" class="zhifu-container1">
    	         <div class="money" ><span id="money">39.8</span>元<span style="color: #ff7e00;"></div>
    	         <input id="addressid" type="hidden" />
    	        <div class="zhifu-type" flag="1" type="wxpay_app">
					<img  src="../images/jiaofei-weixin.png"/>
					<span>微信支付</span>
					<div class="quan"><span></span></div>
				</div>
				<div class="zhifu-type" flag="0" type="alipay_app">
					<img  src="../images/jiafei-zhifubao.png"/>
					<span>支付宝</span>
					<div class="quan"><span style="display: none;"></span></div>
				</div>
				
				<button class="jiao-btn">确认付款</button>
			</div>
		</div>
		<script src="../js/mui.min.js"></script>
		<script src="../js/jquery-1.8.0.min.js"></script>
		<script src="../js/common.js"></script>
		<script type="text/javascript">
		mui(".zhifu-container1").on("tap",".zhifu-type",function(){
			if($(this).attr("flag")=="0"){
				$(this).attr("flag","1").siblings(".zhifu-type").attr("flag","0");
				$(this).find(".quan span").show().end().siblings(".zhifu-type").find(".quan span").hide();
			}
		})
		$(function(){
			var car_id="";//存放
			var wxChannel = null; // 微信支付
			var aliChannel = null; // 支付宝支付
			var channel = null;
			//页面加载时
			mui.plusReady(function(){
				//关闭等待框
				plus.nativeUI.closeWaiting();
			  // 获取支付通道
			 	plus.payment.getChannels(function(channels){
			    aliChannel=channels[0];
			    wxChannel=channels[1];
//			    aliChannel=channels[1];
//			    wxChannel=channels[0];
			  },function(e){
			    alert("获取支付通道失败："+e.message);
			  });
			});
			 //		 检测是否安装支付服务
			function checkServices(pc){
				if(!pc.serviceReady){
					var txt=null;
					switch(pc.id){
						case 'alipay':
						txt='检测到系统未安装“支付宝快捷支付服务”，无法完成支付操作，是否立即安装？';
						break;
						default:
						txt='系统未安装“'+pc.description+'”服务，无法完成支付，是否立即安装？';
						break;
					}
					plus.nativeUI.confirm(txt, function(e){
						if(e.index==0){
							pc.installService();
						}
					}, pc.description);
				}
			}
			var userid=getCookie("userid")
			if(userid==""||userid==null){
				alert("您还没有登录，请先登录")
				location.href="../public/login.html"
			}else{
				
         		var order_id="";
         		order_id=getQueryString("id");
         		if(order_id!=null&&order_id!=""){
         			$.post(net+"/public/index.php?s=api/memberorder/show_order",{"member_id":userid,"id":order_id},function(res){
         				if(res.code=="200"){
         					var str="";
		         			var sum=0;
		         			var sumjifen=0;//总积分
		         		    console.log(res.result.goods_list)
//		         		
		         				var goodlist='';
		         				if(res.result.goods_list!=null&&res.result.goods_list.length!=0){
		         					$.each(res.result.goods_list, function(index,val) {
		         						sum+=this.goods_price*this.goods_num;
		         						sumjifen+=this.goods_point*this.goods_num;
		         						car_id+=this.goods_id+'_'+this.goods_num+',';
		         						var src=net+"public/uploads/home/store/goods/"+this.store_id+"/"+this.goods_image;
		         						goodlist+='<div class="ds-container"><img  src="'+src+'"/><div class="store-con"><h1 class="only-line" style="overflow: hidden;">'+this.goods_name+'<span class="order-p">￥'
		         						        +this.goods_price+'</span></h1><span class="gengxin">共'+this.goods_num+'件商品</span></span><span class="gm-jifen" style="color: #666666;">'+this.goods_point+'积分</span>'
		         				                +'<span class="gm-phone-icon" style="color: #666666;">x'+this.goods_num+'</span></div></div>'
		         					});
		         				}
//		         			
		         			str+='<li><a data-href="" style="display: block;"><h2 class="ds-name">'+res.result.store_name+'</h2>'+goodlist+'</a></li>'	
		         			sum=Math.round(sum*100)/100;
		         			$("#money").html(sum)
		         			
		         			$(".store-list").append(str)
		         		
         				}
         			})
         		}else {
         			alert("页面出错")
         		}
         		//点击确认按钮生成订单
         		mui(".zhifu-container1").on("tap",".jiao-btn",function(){
         			var pay_param={};
         			pay_param.member_id=userid;
         			var reg=/,$/gi;
                    car_id=car_id.replace(reg,"");//截去字符串最后的逗号
         			if(car_id==null||car_id==""){
         				alert("网络错误");
         				return false;
         			}
         			pay_param.cart_id=car_id;
         			pay_param.address_id=$("#addressid").val();
         			if(pay_param.address_id==""||pay_param.address_id==null)
         			{
         				alert("您还没有填收货地址")
         				location.href="address.html?type=1";
         			}
         			$(".zhifu-type").each(function(i){
                     	if($(this).attr("flag")=="1"){
                     		pay_param.payment_code=$(this).attr("type")
                     		if($(this).attr("type")=="alipay_app"){
                     			channel=aliChannel;
                     		}else if($(this).attr("type")=="wxpay_app"){
                     			channel=wxChannel;
                     		}
                     		alert($(this).attr("type"))
                     	}
                     })
         			plus.nativeUI.showWaiting();
         			//请求接口
         			$.post(net+"/public/index.php?s=api/buy/buy_step2",pay_param,function(res){
         				if(res.code=="200"){
         				
         					  $.ajax({
								      type: "post",
								      async: false,
								      url: net+"/public/index.php?s=api/Payment/order_pay/",
								      data: res.result,
								      success: function(res){
		       							plus.nativeUI.closeWaiting();  
		       							alert(JSON.stringify(channel))
									      	checkServices(channel)
									      	alert(JSON.stringify(res.result))
									        plus.payment.request(channel, res.result, function(result) {
//									        	alert("成功"+JSON.stringify(result))
                                                location.href="index.html"
									        }, function(e) {
									        	alert("成功"+JSON.stringify(e))
									        	alert("支付失败")
									        });   						  
								      },
								      error: function(error){
								        callback({'code':1,'msg':"网络连接错误"});
								        return false;
								      }
								  });

         					
         				}
         			})
         		})
			}
		})
		
        
		</script>
	</body>

</html>